global start			; entry point for grub
global kernel_addr		; address of embedded kernel image
global kernel_size		; size of the embedded kernel image
extern multiboot		; entry point in c
 
; Multiboot header
MODULEALIGN equ  1<<0                   ; align loaded modules on page boundaries
MEMINFO     equ  1<<1                   ; provide memory map
FLAGS       equ  MODULEALIGN | MEMINFO  ; this is the Multiboot 'flag' field
MAGIC       equ  0x1BADB002             ; 'magic number' lets bootloader find the header
CHECKSUM    equ -(MAGIC + FLAGS)        ; checksum required
 
section .text
align 4
MultiBootHeader:
   dd MAGIC
   dd FLAGS
   dd CHECKSUM
 
; reserve initial kernel stack space
STACKSIZE equ 0x4000                  ; that's 16k.
 
start:
   mov esp, stack+STACKSIZE           ; set up the stack
   push eax                           ; pass Multiboot magic number
   push ebx                           ; pass Multiboot info structure
 
   call  multiboot                       ; call multiboot which calls the kernel
 
   cli
hang:
   hlt                                ; halt machine should kernel return
   jmp   hang

section .data
kernel_addr dd kernel
align 0x1000				; page aligned so we can map it later
kernel:
   incbin "kernel"
kernel_size dd $-kernel

section .bss
align 32
stack:
   resb STACKSIZE                     ; reserve 16k stack on a quadword boundary
